import { getShopDetail, addOrder } from "@/static/js/pointsMall.js";
import { getUserInfo } from "@/static/js/my.js";
export default {
  data() {
    return {
      shopId: "",
      shopObj: {},
      pageShow: false,
      shopNum: 1,
      maxNum: 0,
      finalPrice: 0,
      userInfo: {}, //用户信息
      finalNum: 0,
    };
  },
  onLoad(e) {
    this.shopId = e.id;
    this.getShopDetail();
  },
  onShow() {
    this.getUserInfo();
  },
  methods: {
    //商品详情
    async getShopDetail() {
      let obj = {
        id: this.shopId,
      };
      let res = await getShopDetail(obj);
      if (res.code === 1) {
        this.shopObj = res.data;
        this.finalPrice = res.data.money;
        this.pageShow = true;
      } else {
        this.$tools.msg(res.msg);
      }
    },

    //获取用户信息
    getUserInfo() {
      getUserInfo().then((res) => {
        this.userInfo = res.data;
        this.maxNum = Math.floor(Number(res.data.money) / this.shopObj.money);
      });
    },

    //跳转积分商城中心
    goHome() {
      uni.navigateTo({
        url: "/pointsMall/index/index",
      });
    },

    //切换数量
    shopNumChange(e) {
      // if (e.value == this.maxNum) {
      // 	this.$tools.msg('抱歉，您的积分余额不足')
      // }
    },

    //确认兑换
    async goOrderDetail() {
      let obj = {
        id: this.shopId,
      };
      let res = await addOrder(obj);
      if (res.code == 1) {
        uni.redirectTo({
          url: `/pointsMall/exchangeResult/index?payStatus=1&id=${this.shopId}&type=${this.shopObj.name_type}`,
        });
      } else {
        this.$tools.msg("抱歉，您的积分余额不足");
      }
    },
  },
};